﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System.Linq;
using ScrumTable.Common;
using ScrumTable.Common.Collections;
using ScrumTable.DL.Data.Schema;

#endregion

namespace ScrumTable.BL.DM.DataManagement
{
    /// <summary>
    /// Contains the basic information about a bug.
    /// </summary>
    public class Bug : ScrumItemBase
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Specifies the bug severity.
        /// </summary>
        public string Severity
        {
            get { return DataObject.GetData(Schema.BugSchema.Severity, string.Empty); }
            set { SetDataWithUndoAction(Schema.BugSchema.Severity, value); }
        }

        /// <summary>
        /// Gets the ScrumItemType of the ScrumItem
        /// </summary>
        public override ScrumItemType ItemType
        {
            get { return ParentProject.Types.BugType; }
        }

        /// <summary>
        /// Gets the parent collection instance.
        /// </summary>
        internal override IDomainCollection ParentCollection
        {
            get { return Parent.SearchCollection<Bug>(); }
        }


        /// <summary>
        /// Gets the domain object schema of the current domain object.
        /// </summary>
        protected override SchemaBase DomainSchema { get { return Schema.BugSchema; } }

        /// <summary>
        /// Returns the name-field schema information.
        /// </summary>
        protected override SchemaBase NameSchema { get { return Schema.BugSchema.Name; } }

        /// <summary>
        /// Returns the description-field schema information.
        /// </summary>
        protected override SchemaBase DescriptionSchema { get { return Schema.BugSchema.Description; } }

        /// <summary>
        /// Returns the memberid-field schema information.
        /// </summary>
        protected override SchemaBase AssignedMemberSchema { get { return Schema.BugSchema.MemberId; } }

        /// <summary>
        /// Returns the ranking-field schema information.
        /// </summary>
        protected override SchemaBase RankingSchema { get { return Schema.BugSchema.Ranking; } }

        /// <summary>
        /// Returns the state-field schema information.
        /// </summary>
        protected override SchemaBase StateSchema { get { return Schema.BugSchema.State; } }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Returns true if the specified state change could be accomplished.
        /// </summary>
        /// <param name="newState">Specifies the new state to validate (to).</param>
        public override bool CanChangeState(ScrumState newState)
        {
            return (base.CanChangeState(newState) && ParentProject.Types.BugType.CanChangeState(State, newState));
        }

        /// <summary>
        /// Initializes the mappings stored in the current instance.
        /// </summary>
        protected override void InitializeMappings()
        {
            base.InitializeMappings();

            PropertySchemaMappings.Add(Schema.BugSchema.Severity, "Severity", true);
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}